<?php
/*
Template Name: Checkout
*/
?>

<?php
$aOptions             = SofaSuppaStore::initOptions( false );
$entrycurrency        = $aOptions[ 'entrycurrency' ];
$checkout_tax         = floatval( $aOptions[ 'checkout_tax' ] );
$checkout_ship        = stripslashes( strip_tags( $aOptions[ 'checkout_ship' ] ) );
$use_stock            = $aOptions[ 'use_stock' ];
$enable_email         = $aOptions[ 'enable_email' ];
$use_checkout_voucher = $aOptions[ 'use_checkout_voucher' ];
// colorbox
$cb_width = ( strlen( $aOptions[ 'cb_width' ] ) > 0 ) ? intval( $aOptions[ 'cb_width' ] ) : 660;
$cb_height = ( strlen( $aOptions[ 'cb_height' ] ) > 0 ) ? intval( $aOptions[ 'cb_height' ] ) : 450;
$cb_height_small = ( strlen( $aOptions[ 'cb_height_small' ] ) > 0 ) ? intval( $aOptions[ 'cb_height_small' ] ) : 300;
?>

<?php get_header(); ?>

<!-- main content start -->

	<!-- title start -->

    <div class="grid_12">
        <h1><?php _e( "Your Basket - Checkout?", "sofa_suppastore" ); ?></h1>
    </div>
    
    <!-- title end -->
    
    <!-- content start -->

    <div id="proddetails" class="grid_12">
    
    	<!-- basket contents start -->
    
        <table id="tblmeta" width="100%" border="0" cellspacing="0" cellpadding="0">
        
          <tr>
            <th scope="col" class="textleft"><?php _e( "Product Name", "sofa_suppastore" ); ?></th>
            <th scope="col" class="center"><?php _e( "Size", "sofa_suppastore" ); ?></th>
            <th scope="col" class="center"><?php _e( "Quantity", "sofa_suppastore" ); ?></th>
            <th scope="col" class="center"><?php _e( "Item Price", "sofa_suppastore" ); ?></th>
            <?php 
			// check if individual shipping price is defined. The column shall be added if any of the products in shopping basket have individual shipping price set.
			$tmp_arr_shipping_price = array();
			if( isset( $_COOKIE[ 'sofasuppastore' ] ) ) {
				foreach( $_COOKIE[ 'sofasuppastore' ] as $name => $value ) {
					$temp_item_arr = explode( '~', $value );
					if( $temp_item_arr[ 6 ] ) array_push( $tmp_arr_shipping_price, $temp_item_arr[ 6 ] );
				}
			}
			if( $tmp_arr_shipping_price ) { 
			?>
            <th scope="col" class="center"><?php _e( "Shipping Price", "sofa_suppastore" ); ?></th>
			<?php } ?>
            <th scope="col" class="center"><?php _e( "Item(s) Total", "sofa_suppastore" ); ?></th>
            <th scope="col" class="center" width="60"><?php _e( "Edit", "sofa_suppastore" ); ?></th>
            <th scope="col" class="textright" width="60"><?php _e( "Remove", "sofa_suppastore" ); ?></th>
          </tr>
          
          <?php
			// what's in da basket?
			$ppal_custom = '';
			$subtotal = 0;
			$custom_shipping_prices = 0;
			$cook_len = 0;
			if( isset( $_COOKIE[ 'sofasuppastore' ] ) ) {
				
				$cook_len = count( $_COOKIE[ 'sofasuppastore' ] ); // the num of cookies
				$iterate = 1;
				foreach( $_COOKIE[ 'sofasuppastore' ] as $name => $value ) {
					
					$single_item_arr = explode( '~', $value ); // 0 - name (ID), 1 - size, 2 - quantity, 3 - price, 4 - selected row, 5 - stock, 6 - shipp
					$ppal_custom .= ( $single_item_arr[ 0 ] . '~' . $single_item_arr[ 1 ] . '~' . $single_item_arr[ 2 ] . '~' . $name . '^' );
					
					echo '<tr id="infoline_' . $iterate . '" class="proddetailstr">';
					echo '<td title="name" class="textleft">';
					echo '<a href="' . get_permalink( $single_item_arr[ 0 ] ) . '" title="' . __( "See this product details.", "sofa_suppastore" ) . '">' . get_the_title( intval( $single_item_arr[ 0 ] ) ) . '</a>';
					echo '</td>';
					echo '<td title="size" class="center">' . $single_item_arr[ 1 ] . '</td>';
					echo '<td title="qty" id="squant_' . $iterate . '" class="center">' . $single_item_arr[ 2 ] . '</td>';
					echo '<td title="price" id="sprice_' . $iterate . '" class="center">';
					echo $entrycurrency . ' ' . number_format( $single_item_arr[ 3 ], 2, '.', '' );
					echo '</td>';
					// if( $checkout_tax ) $tax_separate = $tax_separate + ( ( $single_item_arr[ 3 ] * $single_item_arr[ 2 ] ) * ( $checkout_tax / 100 ) );
					if( $tmp_arr_shipping_price ) {
						$dump_empty_shipping_price = 0;
						if( $single_item_arr[ 6 ] ) {
							$dump_empty_shipping_price = $single_item_arr[ 6 ] * $single_item_arr[ 2 ];
							$custom_shipping_prices = $custom_shipping_prices + $dump_empty_shipping_price;
						}
						echo '<td title="shipp" class="center">' . $entrycurrency . ' ' . number_format( $dump_empty_shipping_price, 2, '.', '' ) . '</td>';
					}
					$calc_item_total = $single_item_arr[ 2 ] * $single_item_arr[ 3 ];
					echo '<td title="total" class="center">' . $entrycurrency . ' ' . number_format( $calc_item_total, 2, '.', '' ) . '</td>';
					echo '<td title="update" class="center">';
					$edit_item_q = '?itemid=' . urlencode( $single_item_arr[ 0 ] ) . '&amp;itemsize=' . urlencode( $single_item_arr[ 1 ] ) . '&amp;itemqty=' . urlencode( $single_item_arr[ 2 ] ) . '&amp;itemprice=' . urlencode( $single_item_arr[ 3 ] ) . '&amp;itemsel=' . urlencode( $single_item_arr[ 4 ] ) . '&amp;itemstock=' . urlencode( $single_item_arr[ 5 ] ) . '&amp;itemshipp=' . urlencode( $single_item_arr[ 6 ] ) . '&amp;cookid=' . urlencode( $name );
					echo '<a href="' . get_template_directory_uri() . '/edit_basket_item.php' . $edit_item_q . '" class="coedit center edititem cboxElement">';
					echo '<img src="' . get_template_directory_uri() . '/images/edit_cart18x18.gif" alt="' . __( "Edit Item", "sofa_suppastore" ) . '" />';
					echo '</a>';
					echo '</td>';
					echo '<td title="remove" class="textright">';
					$remove_item_q = '?itemid=' . urlencode( $single_item_arr[ 0 ] ) . '&amp;itemsize=' . urlencode( $single_item_arr[ 1 ] ) . '&amp;itemqty=' . urlencode( $single_item_arr[ 2 ] ) . '&amp;itemprice=' . urlencode( $single_item_arr[ 3 ] ) . '&amp;itemstock=' . urlencode( $single_item_arr[ 5 ] ) . '&amp;itemshipp=' . urlencode( $single_item_arr[ 6 ] ) . '&amp;cookid=' . urlencode( $name );
					echo '<a href="' . get_template_directory_uri() . '/delete_basket_item.php' . $remove_item_q . '" class="coedit textright delitem cboxElement">';
					echo '<img src="' . get_template_directory_uri() . '/images/delete_cart18x18.gif" alt="' . __( "Delete Item", "sofa_suppastore" ) . '" />';
					echo '</a>';
					echo '</td>';
					echo '</tr>';
					$subtotal = $subtotal + $calc_item_total;
					
					$iterate ++;
				}
				// on page encoding for jQuery
				$ppal_custom = urlencode( $ppal_custom );
			 
			} else {
				echo '<tr id="infoline_1" class="proddetailstr"><td colspan="7">' . __( "No products in the basket.", "sofa_suppastore" ) . '</td></tr>';
			}
		  ?>

        </table>
        
        <!-- basket contents end -->
        
    </div>
    
    <div class="grid_3">
        <a title="<?php _e( "Continue Shopping", "sofa_suppastore" ); ?>" class="continue" href="#" onclick="if(document.referrer){window.open(document.referrer,'_self');}else{history.go(-1);}return false;">
            <?php _e( "Continue Shopping?", "sofa_suppastore" ); ?>
        </a>
    </div>
    
    <div class="grid_9">
    
    	<!-- country selection start -->
    
    	<div class="grid_4 alpha prefix_5">
        
    		<p>
            <select id="selcountry" name="selcountry" size="1">
                <option value="-1" title="0"> -- Select Shipping Country -- </option>
                <?php
				// any option available?
				$arr_countries = explode( "\n", $checkout_ship );
				if( $arr_countries ) {
					foreach( $arr_countries as $k => $v ) {
						$arr_countries[ $k ] = trim( $v ); // trim whitespace
						$unit_obj = explode( '*', $arr_countries[ $k ] );
						echo '<option value="' . $unit_obj[ 1 ] . '" title="' . $unit_obj[ 0 ] . '"> -- ' . $unit_obj[ 0 ] . ' (' . $entrycurrency . ' ' . number_format( $unit_obj[ 1 ], 2, '.', '' ) . ')' . ' -- </option>';
					}
				}
				?>
            </select>
            </p>
            
        </div>
        
        <!-- country selection end -->
        
        <div class="grid_4 alpha prefix_5">
        
        	<!-- total calculations start -->
        
            <table id="tblbill" width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td class="continue"><?php _e( "Subtotal", "sofa_suppastore" ); ?>:</td>
                    <td id="subtotal" class="textright"><?php echo $entrycurrency . ' ' . number_format( $subtotal, 2, '.', '' ); ?></td>
                </tr>
                <tr>
                    <td class="continue"><?php _e( "Shipping/Handling", "sofa_suppastore" ); ?>:</td>
                    <td id="shippinghandling" class="textright"><?php echo $entrycurrency . ' 0.00'; ?></td>
                </tr>
                <?php 
				$tax_calc = 0;
				if( $checkout_tax ) {
					$tax_calc = $subtotal * ( $checkout_tax / 100 );
				?>
                <tr>
                    <td class="continue"><?php echo __( "Tax", "sofa_suppastore" ) . ' (' . $checkout_tax . '%)'; ?>:</td>
                    <td id="thetax" class="textright"><?php echo $entrycurrency . ' ' . number_format( $tax_calc, 2, '.', '' ); ?></td>
                </tr>
                <?php } ?>
                
                <?php if( $use_checkout_voucher == 'yes' ) { ?>
                
                <tr>
                    <td id="voucherlabel"class="continue"><?php _e( "Coupon Code", "sofa_suppastore" ); ?>:</td>
                    <td id="voucher" class="textright">
                    <form id="vcc" name="vcc" method="post" action="">
                    <span id="verifycoupon">
                    <img src="<?php echo get_template_directory_uri(); ?>/images/verify_code_24x24.png" alt="<?php _e( "Verify Coupon Code", "sofa_suppastore" ); ?>" title="<?php echo __( "Verify Coupon Code", "sofa_suppastore" ); ?>" />
                    </span>
                    <input type="text" name="couponcode" id="couponcode" value="" />
                    <?php wp_nonce_field( 'chck_ref_cc', 'sofa_suppastore_cc' ); ?>
                    <input type="hidden" name="discountval" id="discountval" value="" />
                    </form>
                    <span id="inprogress" style="display: none;">&nbsp;</span>
                    </td>
                </tr>
                
                <?php } ?>
                
                <tr>
                    <td class="continue"><?php _e( "Total", "sofa_suppastore" ); ?>:</td>
                    <td id="totalprice" class="textright"><?php echo $entrycurrency . ' 0.00'; ?></td>
                </tr>
                
            </table>
            
            <!-- total calculations end -->
            
        </div>
        
        <!-- payment methods start -->
        
        <div class="textright grid_4 alpha prefix_5">
        	<form id="metapp" name="metapp" method="post" style="visibility: hidden;" action="<?php echo get_template_directory_uri() . ( '/gateways/paypal_start.php' ); ?>">
            <input type="hidden" name="meta_cc" id="meta_cc" value="" />
            <input type="hidden" name="meta_hc" id="meta_hc" value="" />
            </form>
            <?php if( $enable_email == 'yes' ) { ?>
                <a id="co_em" title="<?php _e( "Order by email", "sofa_suppastore" ); ?>" href="#">
                    <img src="<?php echo get_template_directory_uri(); ?>/images/co_email143x37.gif" alt="<?php _e( "Order by email", "sofa_suppastore" ); ?>" />
                </a>
            <?php } ?>
            <a id="co_pp" title="<?php _e( "Checkout with PayPal", "sofa_suppastore" ); ?>" href="#">
                <img src="<?php echo get_template_directory_uri(); ?>/images/co_paypal143x37.gif" alt="<?php _e( "Checkout with PayPal", "sofa_suppastore" ); ?>" />
            </a>
        </div>
        
        <!-- payment methods end -->
        
        <div class="textright grid_4 alpha prefix_5">
        	<p>&nbsp;</p>
        </div>

    </div>
    
<!-- main content end -->
    
	<script type='text/javascript'>
    
        jQuery( document ).ready( function() {
            
            // colorbox
            jQuery( '.edititem' ).colorbox( { width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height . 'px'; ?>", iframe: true } );
            jQuery( '.delitem' ).colorbox( { width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height_small . 'px'; ?>", iframe: true } );
            
            // error handler url
            var error_handler_url = "<?php echo get_template_directory_uri() . ( '/error_handler.php' ); ?>";
            
            // reset
            jQuery( '#couponcode' ).val( '' );
            jQuery( '#discountval' ).val( '' );
            
            // watch for changes at shipping and handling
            var obey_selcountry = jQuery( '#selcountry option:selected' ).attr( 'value' );
            watchChanges( obey_selcountry );
            jQuery( '#selcountry' ).change( function() {
                var obey_this_elem = jQuery( 'option:selected', this ).attr( 'value' );
                watchChanges( obey_this_elem );
            } );
            
            <?php if( $use_checkout_voucher == 'yes' ) { ?>
			
			// coupon codes handler
            jQuery( '#verifycoupon' ).click( function() {
                if( jQuery( '#couponcode' ).val().length > 4 ) {
                    // serialize for ajax
                    var datastr = jQuery( '#vcc' ).serialize();
                    // scenario
                    jQuery( '#vcc' ).toggle( 'fast', function() { jQuery( '#inprogress' ).toggle( 'fast' ).text( '<?php _e( "Verifying...", "sofa_suppastore" ); ?>' ); } ); // remove form silently
                    setTimeout( 'send_and_verify("' + datastr + '")', 1000 );
                } else jQuery( '#couponcode' ).val( '<?php _e( "NOT VALID!", "sofa_suppastore" ); ?>' );
                return false;
            } );
			
			<?php } ?>
            
            // proceed to payment gateway
			<?php if( $enable_email == 'yes' ) { ?>
			
			jQuery( '#co_em' ).click( function() {
                var hc = 0;
                var cc = 0;
                
                if( jQuery( '#selcountry option:selected' ).attr( 'value' ) == -1 ) {
                    jQuery.colorbox( { href: ( error_handler_url + '?errorcode=1' ), iframe: true, width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height_small . 'px'; ?>" } );
                    return false;
                }
                
                if( jQuery( '#selcountry option:selected' ).attr( 'value' ) > -1 ) hc = parseFloat( jQuery( '#selcountry option:selected' ).attr( 'value' ) );
                if( jQuery( '#discountval' ).val() != '' ) cc = parseFloat( jQuery( '#discountval' ).val() );
				
				jQuery( '#meta_cc' ).val( number_format( cc, 2, '.', '' ) );
				jQuery( '#meta_hc' ).val( number_format( hc, 2, '.', '' ) );
				if( val_subtotal() > 0 ) {
					var QS = "?mo=sofasuppastore&loc=" + jQuery( '#selcountry option:selected' ).attr( 'title' ) + "&pri=" + jQuery( '#meta_hc' ).val() + "&dis=" + jQuery( '#meta_cc' ).val();
					jQuery.colorbox( { href: ( "<?php echo get_template_directory_uri() . ( '/mail_order.php' ); ?>" + QS ), iframe: true, width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo ( $cb_height + 100 ) . 'px'; ?>" } );
				} else {
					jQuery.colorbox( { href: ( error_handler_url + '?errorcode=2' ), iframe: true, width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height_small . 'px'; ?>" } );
					return false;
				}
				
				return false;
				
			} );
			
			<?php } ?>

            jQuery( '#co_pp' ).click( function() {
                var hc = 0;
                var cc = 0;
                
                if( jQuery( '#selcountry option:selected' ).attr( 'value' ) == -1 ) {
                    jQuery.colorbox( { href: ( error_handler_url + '?errorcode=1' ), iframe: true, width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height_small . 'px'; ?>" } );
                    return false;
                }
                
                if( jQuery( '#selcountry option:selected' ).attr( 'value' ) > -1 ) hc = parseFloat( jQuery( '#selcountry option:selected' ).attr( 'value' ) );
                if( jQuery( '#discountval' ).val() != '' ) cc = parseFloat( jQuery( '#discountval' ).val() );
                
                <?php if( $use_stock == 'yes' ) { ?>
                
                // chck stock
                var decoded_ppal_custom = decodeURIComponent( "<?php echo $ppal_custom; ?>" );
                decoded_ppal_custom = decoded_ppal_custom.replace( /\+/g, ' ' );
                jQuery.post( "<?php echo get_template_directory_uri() . '/stock_chck.php'; ?>", { "serialdata": decoded_ppal_custom }, 
                    function( data ) {
                        if( data == '' ) {
                            jQuery( '#meta_cc' ).val( number_format( cc, 2, '.', '' ) );
                            jQuery( '#meta_hc' ).val( number_format( hc, 2, '.', '' ) );
                            if( val_subtotal() > 0 ) jQuery( '#metapp' ).submit();
							else {
								jQuery.colorbox( { href: ( error_handler_url + '?errorcode=2' ), iframe: true, width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height_small . 'px'; ?>" } );
								return false;
							}
                        } else {
                            var decoded_response = decodeURIComponent( data );
							decoded_response = decoded_response.replace( /\+/g, ' ' );
                    		jQuery.colorbox( { href: ( error_handler_url + '?errorcode=' + decoded_response ), iframe: true, width: "<?php echo ( $cb_width + 30 ) . 'px'; ?>", height: "<?php echo $cb_height . 'px'; ?>" } );
                    		return false;
                        }
                    } 
                );
                
                <?php } elseif( $use_stock == 'no' ) { ?>
                
                    jQuery( '#meta_cc' ).val( number_format( cc, 2, '.', '' ) );
                    jQuery( '#meta_hc' ).val( number_format( hc, 2, '.', '' ) );
					if( val_subtotal() > 0 ) jQuery( '#metapp' ).submit();
					else {
						jQuery.colorbox( { href: ( error_handler_url + '?errorcode=2' ), iframe: true, width: "<?php echo $cb_width . 'px'; ?>", height: "<?php echo $cb_height_small . 'px'; ?>" } );
						return false;
					}
                    
                <?php } ?>
                
                return false;
            } );
            
        } );
        
        // handle shipping/handling selection
        function watchChanges( elem_value ) {
			
    		// handle subtotal
            var new_value_subtotal_price = parseFloat( <?php echo $custom_shipping_prices; ?> );
            var old_val_shipping = parseFloat( elem_value );
			var sum_custom_and_old = 0;
			
			if( old_val_shipping > -1 ) sum_custom_and_old = old_val_shipping + new_value_subtotal_price;
			else sum_custom_and_old = new_value_subtotal_price;
			
            var old_val_and_curr = decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( sum_custom_and_old, 2, '.', '' );
			
            jQuery( '#shippinghandling' ).text( old_val_and_curr );
			
			// handle total price
			var new_value_total_price = val_subtotal() + val_tax() + sum_custom_and_old;
			
            var new_value_total_price_and_curr = decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( new_value_total_price, 2, '.', '' );
            jQuery( '#totalprice' ).text( new_value_total_price_and_curr );
            
        }
        
        // handlers: subtotal
        function val_subtotal() {
            var old_value_subtotal = jQuery( '#subtotal' ).text();
            var old_value_subtotal_arr = old_value_subtotal.split( ' ' );
            return parseFloat( old_value_subtotal_arr[ 1 ] );
        }
        
        // handlers: tax
        function val_tax() {
            var old_value_tax_val = 0;
            <?php if( $checkout_tax ) { ?>
            var old_value_tax = parseFloat( <?php echo $checkout_tax; ?> );
            var new_value_tax = val_subtotal() * ( old_value_tax / 100 );
            old_value_tax_val = parseFloat( new_value_tax );
            <?php } ?>
            return old_value_tax_val;
        }
        
        // format number
        function number_format( number, decimals, dec_point, thousands_sep ) {
			number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
			var n = !isFinite(+number) ? 0 : +number,
			prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
			sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
			dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
			s = '',
			toFixedFix = function (n, prec) {
				var k = Math.pow(10, prec);
				return '' + Math.round(n * k) / k;
			};
			// Fix for IE parseFloat(0.55).toFixed(0) = 0;
			s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
			if (s[0].length > 3) {
				s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
			}
			if ((s[1] || '').length < prec) {
				s[1] = s[1] || '';
				s[1] += new Array(prec - s[1].length + 1).join('0');
			}
			return s.join(dec);
        }
        
		<?php if( $use_checkout_voucher == 'yes' ) { ?>
		
		// discounted price fix
		function fix_discounted_price( discount_val ) {
			var subtotal_real = 0;
			var i = 1;
			var cookie_lenght = parseInt( <?php echo $cook_len; ?> );
			while( i <= cookie_lenght ) {
				var obj_row_qty = jQuery( '#squant_' + i ).text();
				var obj_row_price = jQuery( '#sprice_' + i ).text();
				
				var single_price_arr = obj_row_price.split( ' ' );
				var single_price_discount = parseFloat( single_price_arr[ 1 ] ) * ( discount_val / 100 );
				subtotal_real += ( number_format( single_price_discount, 2, '.', '' ) * parseInt( obj_row_qty ) );
				i ++;
			}
			
			return subtotal_real;
		}
		
        // chck coupon code
        function send_and_verify( datastr ) {
            jQuery.ajax( {	
                type: "POST",
                url: "<?php echo( get_template_directory_uri() . '/verify_couponcode.php' ); ?>",
                data: datastr,
                cache: false,
                success: function( data ) {
                    if( data == 0 ) {
                        jQuery( '#inprogress' ).toggle( 'fast', function() { jQuery( '#vcc' ).toggle(); } ); // remove message
                        jQuery( '#couponcode' ).val( '<?php _e( "NOT VALID!", "sofa_suppastore" ); ?>' );
                    } else {
                        var voucher_label_text = jQuery( '#voucherlabel' ).text();
                        var chck_for_colon = voucher_label_text.split( ':' );
                        if( chck_for_colon.length > 0 ) jQuery( '#voucherlabel' ).text( chck_for_colon[ 0 ] + ' (- ' + parseFloat( data ) + '%)' + ':' );
                        else jQuery( '#voucherlabel' ).text( voucher_label_text + ' -' + parseFloat( data ) + '%' );
                        jQuery( '#discountval' ).val( parseFloat( data ) );
                        // NN.NN percent off the total price!
                        var old_value_total = jQuery( '#subtotal' ).text();
                        var old_value_total_arr = old_value_total.split( ' ' );
                        var new_value_total = fix_discounted_price( parseFloat( data ) );
                        jQuery( '#inprogress' ).text( ' - ' + decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( new_value_total, 2, '.', '' ) );
						// affect subtotal
						var new_subtotal = parseFloat( old_value_total_arr[ 1 ] ) - new_value_total;
						jQuery( '#subtotal' ).text( decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( new_subtotal, 2, '.', '' ) );
						// affect tax
						if( val_tax() > 0 ) {
							var tmp_tax = val_tax();
							jQuery( '#thetax' ).text( decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( tmp_tax, 2, '.', '' ) );
						}
						// affect total
						var shipping_handling = jQuery( '#shippinghandling' ).text();
                		var old_value_shipping_handling = shipping_handling.split( ' ' );
						var new_total = val_subtotal() + val_tax() + parseFloat( old_value_shipping_handling[ 1 ] );
						jQuery( '#totalprice' ).text( decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( new_total, 2, '.', '' ) );
                    }
                }
            } );
        }
		
		<?php } ?>
        
    </script>

<?php get_footer(); ?>